// Copyright (C) 2025, ZWSOFT Co., LTD.(Guangzhou)
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Globalization;
using System.Windows.Data;
using TestClient.Domain;

namespace TestClient.ViewModel.Util;

public class Vector3dConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value is Vector3d vector)
        {
            return vector.ToString();
        }
        return string.Empty;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value is string str && Vector3d.TryParse(str, out var vector))
        {
            return vector;
        }
        return Binding.DoNothing;
    }
}
